<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>webSocketTest</title>
    <script src="https://code.jquery.com/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/sockjs-client/1.1.0/sockjs.min.js"></script>
    <script src="https://cdn.bootcss.com/stomp.js/2.3.3/stomp.min.js"></script>
</head>
<body>
<div>
    <div class="form-group">
        <label for="connect">WebSocket connection:</label>
        <button id="connect" type="submit">Connect</button>
        <button id="disconnect" type="submit">Disconnect</button>
    </div>
</div>
<script>
    var stompClient = null;
    function connect() {
//        var socket = new SockJS("/myWebSocket");运行后端服务，在浏览器输入localhost:8080/index.html
        var socket = new SockJS("http://192.168.60.30:8082/xinsec-third-api/wsAlarm");//如果前后端分离项目需要拼接具体地址，前后端分离index.html可放在
        stompClient = Stomp.over(socket);
        stompClient.connect({}, function (frame) {
            console.log(frame);
            stompClient.subscribe('/topic/rail', function (body) {
                console.log(body);
            });
        });
    }
    function disconnect() {
        if (stompClient !== null) {
            stompClient.disconnect();
        }
        setConnected(false);
        console.log("Disconnected");
    }
    $(function () {
        $("#connect").click(function (e) {
            connect();
            e.preventDefault();
        });
        $("#disconnect").click(function (e) {
            disconnect();
            e.preventDefault();
        });
    });
</script>
</body>

</html>